//
//  StoreControlViewController.m
//  HaiGoumerMerchant
//
//  Created by apple on 17/1/18.
//  Copyright © 2017年 com.zaoguankeji.www. All rights reserved.
//

#import "StoreControlViewController.h"
#import "GoodsControlTableViewController.h"
#import "YZNavigationMenuView.h"
#import "AddGoodsViewController.h"
@interface StoreControlViewController () <UITextFieldDelegate ,YZNavigationMenuViewDelegate>
@property (nonatomic, strong) CAPSPageMenu *pageMenu;
@property (nonatomic, strong) NSArray *choose;
@property(nonatomic, strong) UITextField * searchTF;
@property (nonatomic, strong) YZNavigationMenuView *menuView ;

@end

@implementation StoreControlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureNavgiationItem];
    [self configurePageMenu];
   
 }

- (YZNavigationMenuView *)menuView {
     if(_menuView == nil) {
         
         YZNavigationMenuView *menuView = [[YZNavigationMenuView alloc] initWithPositionOfDirection:CGPointMake(self.view.frame.size.width - 24, 0) images:nil titleArray:@[@"添加商品",@"参加活动",@"批量选择"]];
         self.menuView = menuView;
    
     }
    return _menuView;
    
    
}
- (void)setUplistSelectView {
    

    self.menuView.clickedBlock = ^(NSInteger index){
        AddGoodsViewController *vc = [UIStoryboard loadStoryboard:AddGoodsViewControllerID];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    };
    [self.view addSubview:_menuView];
    
}
#pragma YZNavigationMenuViewDelegate
- (void)navigationMenuView:(YZNavigationMenuView *)menuView clickedAtIndex:(NSInteger)index;
{
    NSLog(@"------我是第%ld栏",index + 1);
}
- (UIView *)searchTF {
    if(_searchTF == nil) {
    
//    self.searchView  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
//        _searchView.backgroundColor = [UIColor colorWithRed:237/255.0 green:239/255.0 blue:240/255.0 alpha:1];
        
        UITextField *searchTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 8, self.view.bounds.size.width - 10 * 2, 44 - 5*2)];
        searchTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        UIImageView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
        rightView.frame = CGRectMake(-20, 0, 30, searchTF.frame.size.height - 15);
        searchTF.rightView = rightView;
        searchTF.borderStyle = UITextBorderStyleRoundedRect;
        searchTF.backgroundColor = [UIColor whiteColor];
        searchTF.rightViewMode = UITextFieldViewModeUnlessEditing;
        searchTF.returnKeyType = UIReturnKeySearch;
        searchTF.placeholder = @"请输入关键词或手机号";
//        [_searchView addSubview:searchTF];
        searchTF.delegate = self;
        self.searchTF = searchTF;
    }

    return  _searchTF;
}
#pragma mark ------------------------ 搜索框
- (void)setupSearch{
    
   self.navigationItem.titleView  = self.searchTF;
//    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    
   
}


-(void)configureNavgiationItem {
    UIBarButtonItem *rightBackButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"sample"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(showSearchView)];
    self.navigationItem.rightBarButtonItem = rightBackButton;
        UIBarButtonItem *listrightBackButton = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(showListView)];
        self.navigationItem.rightBarButtonItems = @[listrightBackButton,rightBackButton];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];

}

- (void)configurePageMenu {
    GoodsControlTableViewController *Groundingvc = [UIStoryboard loadStoryboard:GoodsControlTableViewControllerID];
    
    Groundingvc.title = @"已上架";
    GoodsControlTableViewController *noGroundingvc = [UIStoryboard loadStoryboard:GoodsControlTableViewControllerID];
    
    noGroundingvc.title = @"已下架";
    
    NSArray *controllerArray = @[Groundingvc, noGroundingvc];
    NSDictionary *parameters = @{
                                 CAPSPageMenuOptionScrollMenuBackgroundColor: [UIColor colorWithRed:30.0/255.0 green:30.0/255.0 blue:30.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionViewBackgroundColor: [UIColor colorWithRed:20.0/255.0 green:20.0/255.0 blue:20.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionSelectionIndicatorColor: [UIColor orangeColor],
                                 CAPSPageMenuOptionBottomMenuHairlineColor: [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionMenuItemFont: [UIFont fontWithName:@"HelveticaNeue" size:13.0],
                                 CAPSPageMenuOptionMenuHeight: @(40.0),
                                 CAPSPageMenuOptionMenuItemWidth: @(90.0),
                                 CAPSPageMenuOptionCenterMenuItems: @(YES)
                                 };
    
    _pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height) options:parameters];
    [self.view addSubview:_pageMenu.view];

    
}

//MARK: gotoPreferences
- (void)showSearchView {
    
   [self setupSearch];
    
    
}

- (void)showListView {
    
    [self setUplistSelectView];
    
    
}
#pragma mark ------------------------ UItextfield
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    
    return YES;
}
//- (void)didTapGoToLeft {
//    NSInteger currentIndex = self.pageMenu.currentPageIndex;
//    
//    if (currentIndex > 0) {
//        [_pageMenu moveToPage:currentIndex - 1];
//    }
//}
//
//- (void)didTapGoToRight {
//    NSInteger currentIndex = self.pageMenu.currentPageIndex;
//    
//    if (currentIndex < self.pageMenu.controllerArray.count) {
//        [self.pageMenu moveToPage:currentIndex + 1];
//    }
//}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
